package cn.ac.jaas.ljx.mybatis.Service;

import org.apache.ibatis.session.SqlSession;

import cn.ac.jaas.ljx.mybatis.MySqlSessionFactory;
import cn.ac.jaas.ljx.mybatis.dao.TeacherDao;
import cn.ac.jaas.ljx.mybatis.model.Teacher;

public class TeacherService {

    private TeacherDao teacherDao;
    private SqlSession sqlSession;
    
    private void init() {
        this.sqlSession = MySqlSessionFactory.openSession();
        this.teacherDao = sqlSession.getMapper(TeacherDao.class);
    }
    
    public Teacher findOneWithCoursesAndAddrById(int id) {
        init();
        try {
            return teacherDao.findOneWithCoursesAndAddrById(id);
        } finally {
            sqlSession.close();
        }
        
    }
}
